package ie.lawlor.amvc.event;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class EventPayloadProxyMappingMapImpl implements
        EventPayloadProxyMapping {

    private Map map = new HashMap();
    public String getSourceMethod(String targetMethod) {
        return (String)map.get(targetMethod);
    }

    public void addMapping(String sourceField, String targetField) {
        map.put(convertToGetter(sourceField), convertToGetter(targetField));
        map.put(convertToSetter(sourceField), convertToSetter(targetField));
    }
    
    public void setMap(Map map){
        for (Iterator itr = map.keySet().iterator(); itr.hasNext();){
            String key = (String)itr.next();
            addMapping(key, (String)map.get(key));
        }
    }
    
    private String convertToGetter(String field){
        return "get" + field.substring(0,1).toUpperCase() + field.substring(1).toLowerCase();
    }
    
    private String convertToSetter(String field){
        return "set" + field.substring(0,1).toUpperCase() + field.substring(1).toLowerCase();
    }
}
